/**
 * @a https://leetcode.cn/problems/validate-stack-sequences/
 */

#include "common.h"


class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
          
    }
};


class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> st;
        int in_sz = pushed.size(), out_sz = popped.size();
        int i = 0, o = 0;
        while(i < in_sz && o < out_sz){
            if(st.empty() || st.top() != popped[o]) st.push(pushed[i++]);
            while(!st.empty() && st.top() == popped[o]){
                st.pop();
                ++o;
            }
        }
        return o == out_sz;
    }
};